Skip to content

gh-152260: Add curses.scr_dump(), scr_restore(), scr_init() and scr_set()#152261

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:curses-scr-dump
Jun 26, 2026
Merged

gh-152260: Add curses.scr_dump(), scr_restore(), scr_init() and scr_set()#152261
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:curses-scr-dump

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Add curses.scr_dump(), scr_restore(), scr_init() and scr_set(), the module-level functions that dump the whole screen to a file and restore it -- the screen-wide counterpart of window.putwin()/getwin().

Unlike putwin()/getwin(), which take a Python file object (mirroring C putwin(WINDOW *, FILE *)), the C scr_* functions are filename-based (they fopen internally), so these wrappers take a filename: a str or a path-like object.

The restored screen is internal curses state (the virtual screen), not a readable window, so the test checks the round-trip by comparing dump files: dump, change the screen, restore, dump again, and assert the two dumps are byte-for-byte identical.

… scr_set()

These module-level functions write the whole virtual screen to a file and
load it back -- the screen-wide counterpart of window.putwin()/getwin().
The filename argument accepts a string or a path-like object.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Jun 26, 2026

Copy link
Copy Markdown

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The implementation looks complete and correct, and the added test checks the 4 added functions.

I don't need these functions, but I'm fine with exposing them in Python since they exist in the C library.

Comment thread Lib/test/test_curses.py
self.assertEqual(win.getmaxyx(), (5, 12))
self.assertEqual(win.instr(2, 0), b' Lorem ipsum')

def test_scr_dump(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name seems to say that scr_dump() is tested, but in fact it tests 4 functions. You may add a comment to say it:

# Test scr_dump(), scr_restore(), scr_init() and scr_set()

Comment thread Lib/test/test_curses.py
@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) June 26, 2026 16:21
@serhiy-storchaka serhiy-storchaka merged commit a85e73b into python:main Jun 26, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants